package com.zoe.onelink.core.util;

import com.zoe.onelink.common.entity.ResultVO;
import com.zoe.onelink.common.enumeration.ExceptionCode;
import com.zoe.onelink.common.exception.ApiException;

/**
 * <p>标题: </p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2021</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: ruansheng
 * @date: 2021-10-22
 */
public class ApiExceptionTranslateUtil {


    /**
     * Api异常翻译
     */
    public static <T> ResultVO<T> translate(ApiException apiException, Object... params) {
        if (apiException == null) {
            return null;
        }
        ExceptionCode exceptionCode = apiException.getExceptionCode();
        String message = LocaleResolverUtil.getMessage(exceptionCode, params);
        return ResultVO.failure(exceptionCode, message, apiException.getError());
    }


}
